package com.wantupai.mvp.framework.lce.impl.fragment;

import android.os.Bundle;
import android.view.View;

import com.wantupai.mvp.framework.lce.MvpLceView;
import com.wantupai.mvp.framework.lce.impl.MvpLceViewImpl;
import com.wantupai.mvp.mvp.MvpPresenter;
import com.wantupai.mvp.mvp.lce.fragment.MvpFragment;


public class MvpLceFragment<D, V extends MvpLceView<D>, P extends MvpPresenter<V>> extends MvpFragment<D, V, P> implements MvpLceView<D>
{

    /**
     * 初始化Lce UI布局（规定你的Lce布局文件的id）
     *
     * @param view
     * @param savedInstanceState
     */
    @Override
    public void onViewCreated(View view, Bundle savedInstanceState)
    {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
    }


    @Override
    public MvpLceViewImpl<D> getDMvpViewimpl()
    {
        if (mDMvpViewimpl == null)
        {
            mDMvpViewimpl = new MvpLceViewImpl();
        }
        return (MvpLceViewImpl) mDMvpViewimpl;
    }

    private void initView(View v)
    {
        getDMvpViewimpl().initView(v);
        getDMvpViewimpl().setOnClickErrorListener(this::onErrorClick);
    }

    @Override
    public void noMoreData()
    {
        getDMvpViewimpl().noMoreData();
    }

    @Override
    public void loadMoreError()
    {
        getDMvpViewimpl().loadMoreError();
    }

    @Override
    public void loadRefreshError()
    {
        getDMvpViewimpl().loadRefreshError();
    }

    @Override
    public void loadData(boolean pullToRefresh)
    {
        getDMvpViewimpl().loadData(pullToRefresh);
    }

    @Override
    public void bindData(D data)
    {
        getDMvpViewimpl().bindData(data);
    }

    @Override
    public void onErrorClick(View v)
    {
        loadData(false);
    }

    @Override
    public void refreshComplete()
    {

    }
}